#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>


class Solution1 {
public:
    vector<vector<int>> threeSum(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        vector<vector<int>> vv;
        int n = nums.size();
        for (int i = 0; i < n;)
        {
            if (nums[i] > 0) break;
            int left = i + 1, right = n - 1;
            while (left < right)
            {
                if (nums[left] + nums[right] < (-nums[i]))
                    left++;
                else if (nums[left] + nums[right] > (-nums[i]))
                    right--;
                else
                {
                    vv.push_back({ nums[i],nums[left],nums[right] });
                    left++, right--;
                    while (left < right && nums[left] == nums[left - 1])
                        left++;
                    while (left < right && nums[right] == nums[right + 1])
                        right--;
                }

            }
            i++;
            while (i < n && nums[i] == nums[i - 1])
                i++;
        }
        return vv;
    }
};

class Solution2 {
public:
    vector<vector<int>> fourSum(vector<int>& nums, int target) {
        sort(nums.begin(), nums.end());
        vector<vector<int>> vv;
        int n = nums.size();
        for (int i = 0; i < n;)
        {
            for (int j = i + 1; j < n;)
            {
                int left = j + 1, right = n - 1;
                long long sum = (long long)target - nums[i] - nums[j];
                while (left < right)
                {
                    if (nums[left] + nums[right] < sum)
                        left++;
                    else if (nums[left] + nums[right] > sum)
                        right--;
                    else
                    {
                        vv.push_back({ nums[i],nums[j],nums[left],nums[right] });
                        left++, right--;
                        while (left < right && nums[left] == nums[left - 1])
                            left++;
                        while (left < right && nums[right] == nums[right + 1])
                            right--;
                    }
                }
                j++;
                while (j < n && nums[j] == nums[j - 1])
                    j++;
            }
            i++;
            while (i < n && nums[i] == nums[i - 1])
                i++;
        }
        return vv;
    }
};

int main()
{

	return 0;
}